package com.grass.p019lv.game;

import android.content.Intent;
import android.net.Uri;
import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;
import androidx.recyclerview.widget.GridLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.GameAccountBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.recycler.RxRecyclerViewDividerTool;
import com.androidx.p013lv.base.utils.DeviceIDUtils;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.mine.bean.PayBean;
import com.google.gson.Gson;
import com.grass.p019lv.databinding.ActivityGameRechargeBinding;
import com.grass.p019lv.game.adapter.GameGoldAdapter;
import com.grass.p019lv.game.bean.GameChargeBean;
import com.grass.p019lv.game.bean.GameRechargeBean;
import com.grass.p019lv.game.bean.GameTransferBean;
import com.grass.p019lv.game.view.GameDialogUtils;
import com.grass.p019lv.game.view.LoadingDialog;
import com.gyf.immersionbar.ImmersionBar;
import com.lzy.okgo.model.Response;
import java.util.ArrayList;
import java.util.List;

/* renamed from: com.grass.lv.game.GameRechargeActivity */
public class GameRechargeActivity extends BaseActivity<ActivityGameRechargeBinding> implements View.OnClickListener, ItemClickListener {
    GameRechargeBean bean = new GameRechargeBean();
    private GameAccountBean gameAccountBean;
    private GameGoldAdapter goldAdapter;
    private List<GameChargeBean.GameChargeData> goldVipList;
    LoadingDialog loadingDialog;
    private SparseArray<View> playViews = new SparseArray<>();
    private int seletedPlayPosition = 0;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return R.layout.activity_game_recharge;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityGameRechargeBinding) this.binding).toolBar).init();
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        ((ActivityGameRechargeBinding) this.binding).setClick(new OnClick());
        ((ActivityGameRechargeBinding) this.binding).tvHint.getPaint().setFlags(8);
        ((ActivityGameRechargeBinding) this.binding).llWx.setOnClickListener(this);
        ((ActivityGameRechargeBinding) this.binding).imgWx.setOnClickListener(this);
        ((ActivityGameRechargeBinding) this.binding).llZfb.setOnClickListener(this);
        ((ActivityGameRechargeBinding) this.binding).imgZfb.setOnClickListener(this);
        ((ActivityGameRechargeBinding) this.binding).llYsf.setOnClickListener(this);
        ((ActivityGameRechargeBinding) this.binding).imgYsf.setOnClickListener(this);
        this.playViews.append(0, ((ActivityGameRechargeBinding) this.binding).imgWx);
        this.playViews.append(1, ((ActivityGameRechargeBinding) this.binding).imgZfb);
        this.playViews.append(2, ((ActivityGameRechargeBinding) this.binding).imgYsf);
        this.loadingDialog = new LoadingDialog();
    }

    /* access modifiers changed from: protected */
    @Override // androidx.fragment.app.FragmentActivity
    public void onResume() {
        super.onResume();
        getGameAccount();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getGameAccount() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getGameAccount(), new HttpCallback<BaseRes<GameAccountBean>>("getGameAccount") {
            /* class com.grass.p019lv.game.GameRechargeActivity.C30191 */

            public void onLvSuccess(BaseRes<GameAccountBean> baseRes) {
                if (GameRechargeActivity.this.binding != null && 200 == baseRes.getCode()) {
                    GameRechargeActivity.this.gameAccountBean = baseRes.getData();
                    TextView textView = ((ActivityGameRechargeBinding) GameRechargeActivity.this.binding).tvGameMoney;
                    textView.setText("游戏余额: " + GameRechargeActivity.this.gameAccountBean.getGameBalance());
                    TextView textView2 = ((ActivityGameRechargeBinding) GameRechargeActivity.this.binding).tvMoney;
                    textView2.setText("钱包余额: " + GameRechargeActivity.this.gameAccountBean.getBalance());
                    TextView textView3 = ((ActivityGameRechargeBinding) GameRechargeActivity.this.binding).tvIncomeMoney;
                    textView3.setText("累计收益: " + GameRechargeActivity.this.gameAccountBean.getProfit());
                }
            }
        });
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initData() {
        super.initData();
        this.goldVipList = new ArrayList();
        GameGoldAdapter gameGoldAdapter = new GameGoldAdapter();
        this.goldAdapter = gameGoldAdapter;
        gameGoldAdapter.setItemListener(this);
        ((ActivityGameRechargeBinding) this.binding).recycler.setLayoutManager(new GridLayoutManager(this, 3));
        ((ActivityGameRechargeBinding) this.binding).recycler.addItemDecoration(new RxRecyclerViewDividerTool(UiUtils.dp2px(5)));
        ((ActivityGameRechargeBinding) this.binding).recycler.setAdapter(this.goldAdapter);
        getGameChargeList();
    }

    private void getGameChargeList() {
        this.loadingDialog.show(getSupportFragmentManager(), "loadingDialog");
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getGameChargeList(), new HttpCallback<BaseRes<GameChargeBean>>("getGameChargeList") {
            /* class com.grass.p019lv.game.GameRechargeActivity.C30202 */

            public void onLvSuccess(BaseRes<GameChargeBean> baseRes) {
                if (GameRechargeActivity.this.binding != null) {
                    if (GameRechargeActivity.this.loadingDialog != null) {
                        GameRechargeActivity.this.loadingDialog.dismiss();
                    }
                    if (baseRes.getCode() == 200) {
                        GameRechargeActivity.this.goldVipList = baseRes.getData().getData();
                        GameRechargeActivity.this.goldAdapter.setData(GameRechargeActivity.this.goldVipList);
                        if (GameRechargeActivity.this.goldVipList != null && GameRechargeActivity.this.goldVipList.size() > 0) {
                            GameRechargeActivity.this.clickGoldCard(0);
                            return;
                        }
                        return;
                    }
                    ToastUtils.getInstance().showSigh(baseRes.getMsg());
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void setVipType(List<GameChargeBean.PayTypes> list, int i, int i2) {
        this.bean.setPrice(i);
        this.bean.setProductId(i2);
        if (this.binding != null) {
            initGone();
            if (list != null && list.size() > 0) {
                boolean z = false;
                boolean z2 = false;
                boolean z3 = false;
                for (GameChargeBean.PayTypes payTypes : list) {
                    if (payTypes.getPayMent().equals("1001")) {
                        ((ActivityGameRechargeBinding) this.binding).llZfb.setVisibility(0);
                        z2 = true;
                    } else if (payTypes.getPayMent().equals("1002")) {
                        ((ActivityGameRechargeBinding) this.binding).llWx.setVisibility(0);
                        z = true;
                    } else if (payTypes.getPayMent().equals("1003")) {
                        ((ActivityGameRechargeBinding) this.binding).llYsf.setVisibility(0);
                        z3 = true;
                    }
                }
                if (z) {
                    this.playViews.get(0).setSelected(true);
                    this.bean.setRechType(2);
                } else if (z2) {
                    this.playViews.get(1).setSelected(true);
                    this.bean.setRechType(1);
                } else if (z3) {
                    this.playViews.get(2).setSelected(true);
                    this.bean.setRechType(3);
                }
            }
        }
    }

    /* access modifiers changed from: package-private */
    public void initGone() {
        ((ActivityGameRechargeBinding) this.binding).llWx.setVisibility(8);
        ((ActivityGameRechargeBinding) this.binding).llZfb.setVisibility(8);
        ((ActivityGameRechargeBinding) this.binding).llYsf.setVisibility(8);
        this.bean.setRechType(0);
        for (int i = 0; i < 3; i++) {
            this.playViews.get(i).setSelected(false);
        }
    }

    public void logicplay() {
        if (!NetUtil.isNetworkAvailable()) {
            ToastUtils.getInstance().showSigh(UiUtils.getString(R.string.hit_no_net));
        } else if (this.bean.getRechType() == 0) {
            ToastUtils.getInstance().showSigh("請選擇支付型別");
        } else if (this.bean.getPrice() == 0) {
            ToastUtils.getInstance().showSigh("請選擇購買商品");
        } else {
            this.loadingDialog.show(getSupportFragmentManager(), "loadingDialog");
            String gameRecharge = UrlManager.getInsatance().gameRecharge();
            this.bean.setDeviceId(DeviceIDUtils.getUniqueId(this));
            HttpUtils.getInsatance().post(gameRecharge, new Gson().toJson(this.bean), new HttpCallback<BaseRes<PayBean>>("payment") {
                /* class com.grass.p019lv.game.GameRechargeActivity.C30213 */

                public void onLvSuccess(BaseRes<PayBean> baseRes) {
                    if (GameRechargeActivity.this.getActivity() != null && GameRechargeActivity.this.binding != null) {
                        if (GameRechargeActivity.this.loadingDialog != null) {
                            GameRechargeActivity.this.loadingDialog.dismiss();
                        }
                        if (baseRes.getCode() == 200) {
                            PayBean data = baseRes.getData();
                            ARouter.getInstance().build(Constance.RECHARGE_HINT_ACTIVITY).navigation();
                            try {
                                Intent intent = new Intent();
                                intent.setAction("android.intent.action.VIEW");
                                intent.setData(Uri.parse(data.getUrl()));
                                GameRechargeActivity.this.startActivity(intent);
                            } catch (Exception e) {
                                e.printStackTrace();
                                ToastUtils.getInstance().showWeak("支付失敗");
                            }
                        } else {
                            ToastUtils.getInstance().showWeak(baseRes.getMsg());
                        }
                    }
                }
            });
        }
    }

    public void onClick(View view) {
        if (view.getId() == R.id.ll_wx || view.getId() == R.id.img_wx) {
            this.seletedPlayPosition = 0;
            this.bean.setRechType(2);
        }
        if (view.getId() == R.id.ll_zfb || view.getId() == R.id.img_zfb) {
            this.seletedPlayPosition = 1;
            this.bean.setRechType(1);
        }
        if (view.getId() == R.id.ll_ysf || view.getId() == R.id.img_ysf) {
            this.seletedPlayPosition = 2;
            this.bean.setRechType(3);
        }
        int i = 0;
        while (i < 3) {
            this.playViews.get(i).setSelected(i == this.seletedPlayPosition);
            i++;
        }
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        clickGoldCard(i);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void clickGoldCard(int i) {
        for (int i2 = 0; i2 < this.goldVipList.size(); i2++) {
            this.goldVipList.get(i2).setSelected(false);
        }
        this.goldVipList.get(i).setSelected(true);
        this.goldAdapter.setData(this.goldVipList);
        GameChargeBean.GameChargeData gameChargeData = this.goldVipList.get(i);
        setVipType(gameChargeData.getPayTypes(), gameChargeData.getPrice(), gameChargeData.getProductId());
    }

    /* renamed from: com.grass.lv.game.GameRechargeActivity$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void btnBack() {
            GameRechargeActivity.this.finish();
        }

        public void goDetails() {
            if (!GameRechargeActivity.this.isOnClick()) {
                Intent intent = new Intent(GameRechargeActivity.this, GameTransactionInfoActivity.class);
                intent.putExtra(Key.TXT, "资金明细");
                GameRechargeActivity.this.startActivity(intent);
            }
        }

        public void goWithDrawDetails() {
            if (!GameRechargeActivity.this.isOnClick()) {
                Intent intent = new Intent(GameRechargeActivity.this, GameWithdrawHistoryActivity.class);
                intent.putExtra(Key.TXT, "提现记录");
                GameRechargeActivity.this.startActivity(intent);
            }
        }

        public void goWithDraw() {
            if (!GameRechargeActivity.this.isOnClick()) {
                GameRechargeActivity.this.startActivity(new Intent(GameRechargeActivity.this, GameWithdrawActivity.class));
            }
        }

        public void goHint() {
            if (!GameRechargeActivity.this.isOnClick()) {
                GameRechargeActivity.this.startActivity(new Intent(GameRechargeActivity.this, SoluationActivity.class));
            }
        }

        public void goRecharge() {
            if (!GameRechargeActivity.this.isOnClick()) {
                GameRechargeActivity.this.logicplay();
            }
        }

        public void goTransfer() {
            GameDialogUtils instance = GameDialogUtils.getInstance();
            GameRechargeActivity gameRechargeActivity = GameRechargeActivity.this;
            instance.createTransferDialog(gameRechargeActivity, gameRechargeActivity.gameAccountBean.getBalance(), GameRechargeActivity.this.gameAccountBean.getGameBalance(), new GameDialogUtils.OnSelectConfirmListener() {
                /* class com.grass.p019lv.game.GameRechargeActivity.OnClick.C30231 */

                @Override // com.grass.p019lv.game.view.GameDialogUtils.OnSelectConfirmListener
                public void onConfirmSelect(String str, int i) {
                    GameRechargeActivity.this.walletTransfer(str, i);
                }
            });
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void walletTransfer(String str, int i) {
        String walletTransfer = UrlManager.getInsatance().walletTransfer();
        this.loadingDialog.show(getSupportFragmentManager(), "loadingDialog");
        HttpUtils.getInsatance().post(walletTransfer, JsonParams.build().add("amount", Double.valueOf(str)).add("transferType", Integer.valueOf(i)).commit(), new HttpCallback<BaseRes<GameTransferBean>>("walletTransfer") {
            /* class com.grass.p019lv.game.GameRechargeActivity.C30224 */

            public void onLvSuccess(BaseRes<GameTransferBean> baseRes) {
                if (GameRechargeActivity.this.loadingDialog != null) {
                    GameRechargeActivity.this.loadingDialog.dismiss();
                }
                if (200 == baseRes.getCode()) {
                    ToastUtils.getInstance().showCorrect("划转成功");
                    GameRechargeActivity.this.getGameAccount();
                    return;
                }
                ToastUtils.getInstance().showWeak(baseRes.getMsg());
            }

            @Override // com.androidx.p013lv.base.http.callback.HttpCallback, com.lzy.okgo.callback.AbsCallback, com.lzy.okgo.callback.Callback
            public void onError(Response<BaseRes<GameTransferBean>> response) {
                super.onError(response);
                if (GameRechargeActivity.this.loadingDialog != null) {
                    GameRechargeActivity.this.loadingDialog.dismiss();
                }
            }
        });
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag("walletTransfer");
        HttpUtils.getInsatance().cancelTag("payment");
        HttpUtils.getInsatance().cancelTag("getGameChargeList");
        HttpUtils.getInsatance().cancelTag("getGameAccount");
    }
}
